home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 / Ham Radio 2000.iso / ham2000 / misc / icom_cat / program3.bas < prev    next >
BASIC Source File  |  1993-07-30  |  6KB  |  230 lines

  1. '
  2. ' Program 1 (MODE AND VFO SETTING)
  3. '
  4. ' Program taken from the "CT-17 Communication Interface-V (CI-V) Level
  5. ' Converter Instruction Manual". Program converted to IBM QBASIC by Bill
  6. ' Heaton, N7WRI.
  7. '
  8. DEFINT G-Z
  9.  
  10. DECLARE SUB DoCommand (Cmd AS INTEGER, Arg AS STRING)
  11. DECLARE SUB GetReply ()
  12. DECLARE SUB SetupBCD ()
  13. DECLARE SUB SetupCOM ()
  14. DECLARE SUB ShowMainPrompts ()
  15.  
  16. DECLARE FUNCTION GetChan$ ()
  17. DECLARE FUNCTION STRTOHEX$ (Str AS STRING)
  18.  
  19. DIM SHARED BCD$(100)
  20.  
  21. '
  22. ' Configuration Information
  23. '
  24.  
  25. CONST RA = &H3C                 ' Receive Address (IC-737)
  26. CONST TA = &HE0                 ' Transmit Address (Computer)
  27.  
  28. CONST PORT$ = "COM1"            ' Serial Port to use
  29. CONST PORTNO = 1                ' Serial Port to use
  30. CONST CONF$ = "1200,N,8,1"      ' Baud rate, Parity, Bits, Stop Bits
  31.  
  32. CONST SHOWCOM = 1               ' Show Com Packets ( 0=No, 1=Yes)
  33.  
  34. '
  35. ' Initialize
  36. '
  37.  
  38. SetupBCD
  39. SetupCOM
  40. ShowMainPrompts
  41.  
  42. '
  43. '  Endless loop until an event handler kills us
  44. '
  45. DO UNTIL TRUE
  46. LOOP
  47.  
  48. '
  49. ' Event Handlers
  50. '
  51. Serial: GetReply:           RETURN
  52. F1: DoCommand &H8, "":      RETURN
  53. F2: DoCommand &H8, GetChan$: RETURN
  54. F3: DoCommand &H9, "":      RETURN
  55. F4: DoCommand &HA, "":      RETURN
  56. F5: DoCommand &HB, "":      RETURN
  57. F6: DoCommand &HE, CHR$(1): RETURN
  58. F7: DoCommand &HE, CHR$(0): RETURN
  59. F0: CLOSE : SYSTEM
  60.  
  61. ' +---------------------------------------------------------------------+
  62. ' |                                                                     |
  63. ' |                      ICOM CI-V Packet Layout                        |
  64. ' |     +----------+----------+---------+---------+---------+------+    |
  65. ' |     | Preamble | Transmit | Receive | Command | Sub     | EOM  |    |
  66. ' |     | <FE><FE> | Address  | Address |         | Command | <FD> |    |
  67. ' |     +----------+----------+---------+---------+---------+------+    |
  68. ' |                                                                     |
  69. ' |     A packet consists of two bytes of &HFE, one byte for the        |
  70. ' |     transmit address (Controller), One byte receive address         |
  71. ' |     (Rig), one byte command, one to five byte subcommand, and       |
  72. ' |     finally the tail of one byte of &HFD.                           |
  73. ' |                                                                     |
  74. ' +---------------------------------------------------------------------+
  75. SUB DoCommand (Cmd AS INTEGER, SubCmd AS STRING)
  76.  
  77.   '
  78.   ' Create the packet and send it out
  79.   '
  80.   Out$ = CHR$(&HFE) + CHR$(&HFE) + CHR$(RA) + CHR$(TA) + CHR$(Cmd) + SubCmd + CHR$(&HFD)
  81.   PRINT #1, Out$;
  82.  
  83.   '
  84.   ' If we're watching packets, send to the screen in hex
  85.   '
  86.   IF SHOWCOM THEN
  87.     CLS
  88.     LOCATE 17, 1: PRINT "Sent: "
  89.     LOCATE 17, 7: PRINT STRTOHEX$(Out$);
  90.     LOCATE 18, 1: PRINT "Echo: "
  91.     LOCATE 19, 1: PRINT "Back: "
  92.   END IF
  93. END SUB
  94.  
  95. '
  96. ' Get a memory channel from the user
  97. '
  98. FUNCTION GetChan$
  99.   I = 0
  100.   WHILE I = 0
  101.     CLS
  102.     LOCATE 12, 30: INPUT "Enter Memory Channel: ", I
  103.     IF I < 1 OR I > 9999 THEN I = 0
  104.   WEND
  105.  
  106.   IF I < 100 THEN
  107.     GetChan$ = BCD$(I)
  108.   ELSE
  109.     I$ = RIGHT$("0000" + MID$(STR$(I), 2), 4)
  110.     DA$ = ""
  111.  
  112.     FOR K = 1 TO 4 STEP 2
  113.       DA$ = DA$ + BCD$(VAL(MID$(I$, K, 2)))
  114.     NEXT K
  115.     GetChan$ = DA$
  116.   END IF
  117. END FUNCTION
  118.  
  119. '
  120. ' GetReply      - Character has arrived from rig, stuff it away until
  121. '                 have an entire packet and display it.
  122. '
  123. SUB GetReply
  124.   STATIC Hold$
  125.  
  126.   '
  127.   ' Accumulate the Reply, if its not end of packet get out early
  128.   '
  129.   Hold$ = Hold$ + INPUT$(LOC(PORTNO), PORTNO)
  130.   IF INSTR(Hold$, CHR$(&HFD)) = 0 THEN
  131.     EXIT SUB
  132.   END IF
  133.  
  134.   '
  135.   ' Echo replys to the screen if we were told to
  136.   '
  137.   IF SHOWCOM THEN
  138.     IF MID$(Hold$, 3, 1) = CHR$(TA) THEN
  139.       LOCATE 19, 7: PRINT STRTOHEX$(Hold$);
  140.     
  141.       SELECT CASE MID$(Hold$, 5, 1)
  142.         CASE CHR$(&HFB)
  143.             LOCATE 25, 1: PRINT "[OK]     ";
  144.         CASE CHR$(&HFA)
  145.             LOCATE 25, 1: PRINT "[ERROR]  ";
  146.         CASE ELSE
  147.             LOCATE 25, 1: PRINT "[Unknown]";
  148.       END SELECT
  149.     ELSE
  150.       LOCATE 18, 7: PRINT STRTOHEX$(Hold$);
  151.     END IF
  152.   END IF
  153.  
  154.   ' Get ready for next reply
  155.   Hold$ = ""
  156. END SUB
  157.  
  158. '
  159. '  Set up the BCD string array
  160. '
  161. SUB SetupBCD
  162.   FOR M = 0 TO 9
  163.     FOR N = 0 TO 9
  164.       BCD$(10 * M + N) = CHR$(16 * M + N)
  165.     NEXT N
  166.   NEXT M
  167. END SUB
  168.  
  169. '
  170. '  Setup the channel to the serial port
  171. '
  172. SUB SetupCOM
  173.  
  174.   OPEN PORT$ + ":" + CONF$ + ",CD0,CS0,DS0,OP0,RS" FOR RANDOM AS #1
  175.   ON COM(PORTNO) GOSUB Serial
  176.   COM(PORTNO) ON
  177. END SUB
  178.  
  179. SUB ShowMainPrompts
  180.  
  181.   '
  182.   '  Paint the prompts
  183.   '
  184.   CLS
  185.   M1$ = "╔═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦═══════╦══════╗"
  186.   M2$ = "║  F1   ║  F2   ║  F3   ║  F4   ║  F5   ║  F6   ║  F7   ║       ║       ║ F10  ║"
  187.   M3$ = "║ Memory║ Select║  MW   ║ M>VFO ║  MC   ║ Scan ║ Scan █║       ║       ║ EXIT ║"
  188.   M4$ = "╚═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩═══════╩══════╝"
  189.  
  190.   LOCATE 21, 1: PRINT M1$;
  191.   LOCATE 22, 1: PRINT M2$;
  192.   LOCATE 23, 1: PRINT M3$;
  193.   LOCATE 24, 1: PRINT M4$;
  194.   VIEW PRINT 1 TO 20
  195.  
  196.   '
  197.   '  Setup function key handlers for each options
  198.   '
  199.   ON KEY(1) GOSUB F1
  200.   ON KEY(2) GOSUB F2
  201.   ON KEY(3) GOSUB F3
  202.   ON KEY(4) GOSUB F4
  203.   ON KEY(5) GOSUB F5
  204.   ON KEY(6) GOSUB F6
  205.   ON KEY(7) GOSUB F7
  206.   ON KEY(10) GOSUB F0
  207.   '
  208.   '  Turn the key handlers on
  209.   '
  210.   FOR I = 1 TO 10
  211.     KEY(I%) ON
  212.   NEXT I
  213.  
  214.   KEY(8) OFF
  215.   KEY(9) OFF
  216. END SUB
  217.  
  218. ' STRTOHEX$ - Translate all the characters in a string to hex and
  219. '             return the resulting string.
  220. '
  221. FUNCTION STRTOHEX$ (Str AS STRING)
  222. Scn$ = ""
  223. FOR I = 1 TO LEN(Str)
  224.      C$ = HEX$(ASC(MID$(Str, I, 1)))
  225.      Scn$ = Scn$ + C$ + " "
  226.   NEXT I
  227. STRTOHEX$ = Scn$
  228. END FUNCTION
  229.  
  230.